<!DOCTYPE html>
<html lang="cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="shortcut icon" href="/assets/img/efo-favicon.png" />
    <link rel="stylesheet" href="/assets/css/bootstrap.min.css">
    <link rel="stylesheet" href="/assets/css/fileinput.min.css">
    <link rel="stylesheet" href="/assets/css/glyphicons.css">
    <script src="/assets/js/popper.min.js"></script>
    <script src="/assets/js/jquery-3.3.1.js"></script>
    <script src="/assets/js/bootstrap.min.js"></script>
    <script src="/assets/js/layer.js"></script>
    <script src="/assets/js/vue.js"></script>
    <script src="/assets/js/piexif.min.js"></script>
    <script src="/assets/js/sortable.min.js"></script>
    <script src="/assets/js/purify.min.js"></script>
    <script src="/assets/js/fileinput.min.js"></script>
    <script src="/assets/js/theme.js"></script>
    <script src="/assets/js/utils.js"></script>
    <link rel="stylesheet" href="/assets/css/style.css" />
    <title>上传</title>
</head>

<body id="particles-js">
    <br />
    <div class="container">
        <div class="row">
            <div class="col-sm-12 col-10 offset-1 offset-sm-0">
                <div class="row content-box rounded">
                    <div class="col-sm-12 col-12 offset-sm-0">
                        <br />
                        <div class="row form-inline">
                            <div class="col-sm-3 col-5">
                                <select id="category-id" class="form-control w-100" title="分类">
                                    <option value="0">未分类</option>
                                </select>
                            </div>
                            <div class="col-sm-6 col-3">
                                <input class="form-control w-100" title="标签" type="text" id="tag"
                                    placeholder="文件标签，多个标签用空格分隔" />
                            </div>
                            <div class="col-sm-3 col-4">
                                <input class="form-control w-100" title="加密密码" type="password" id="psd"
                                    placeholder="加密密码" />
                            </div>
                        </div>
                        <br />
                    </div>
                    <div class="col-sm-12 col-12 offset-sm-0">
                        <textarea class="form-control" rows="5" id="description" title="描述"
                            placeholder="文件描述"></textarea>
                    </div>
                    <div class="col-sm-12 col-12 offset-sm-0"><br />
                        <input id="file-input" class="form-control file" multiple data-max-file-count="100" name="file"
                            type="file" /><br />
                    </div>
                </div>
            </div>
        </div>
        <br />
        <div class="row text-center" id="footer"></div>
        <br />
    </div>
    <script src="/assets/js/particles.js"></script>
    <script src="/assets/js/default.js"></script>
    <!-- <script src="/assets/js/upload.js"></script> -->
</body>
<script>
    $(function () {
        console.log('就绪')
        $.get("/category/all", function (data) {
            var json = JSON.parse(data);
            console.log(json)
            var option = "";
            // 加载分类信息
            $.each(json, function (i, category) {
                option += "<option value='" + category.id + "'>" + category.name + "</option>";
            });
            if (!isEmpty(option)) {
                $("#category-id").html(option);
            }
        });
    })

    $("#file-input").fileinput({
        uploadUrl: "/file",
        uploadAsync: true,
        maxFileCount: 100,
        previewFileType: ['image', 'html', 'text', 'video', 'audio', 'flash'],
        uploadExtraData: function () {
            return {
                categoryId: $("#category-id").val(),
                tag: $("#tag").val(),
                psd: $("#psd").val(),
                description: $("#description").val(),
                prefix: getQuery("prefix")
            };
        },
        maxFilePreviewSize: 51200
    }).on('fileuploaded', function (event, data, previewId, index) {
        var json = data.response;
        if (json.status === "success") {
            alerts("上传成功");
        } else {
            alerts("上传失败，文件不合法");
        }
    });
</script>

</html>